﻿using XFControls.Utils;
using XFControls.XFPanels.XFPanelItems;
using System.Drawing;

namespace XFSenseUI.XFItems.SenseControls
{
    public class SenseControlCheckbox : SenseControl
    {
        private int _height;

        public bool Checked { get; set; }

        public SenseControlCheckbox()
        {
            ItemRectangle = new Rectangle();
            _height = -1;
            ItemType = XFItemType.Clickable;
        }

        public override int GetHeight()
        {
            if (_height > -1)
                return _height;

            ItemRectangle = this.GetImageRec("check-checked");
            _height = ItemRectangle.Height;
            return _height;
        }

        public override void ResetHeight()
        {
            _height = -1;
        }

        public override void ItemPaint(Graphics g, int x, int y)
        {
            DrawUI(Checked ? "check-checked" : "check-unchecked", g, new Rectangle(x, y, ItemRectangle.Width, ItemRectangle.Height));
        }

        public override XFItemClickResult GetClickResult()
        {
            Checked = !Checked;
            return base.GetClickResult();
        }
    }
}
